
import Vue from 'vue'
import App from './App.vue'
import router from './router/router.js'
// 导入element
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 导入全局样式
import './assets/css/globel.less'
// 导入axios
import axios from 'axios'
// 导入表格插件
import TableTree from 'vue-table-with-tree-grid'
// 导入时间格式化插件
import moment from 'moment'
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
// 导入mock
import './mock/index.js'

// 导入nprogress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.config.productionTip = false
Vue.use(ElementUI)
// 表格树
Vue.component('table-tree', TableTree)
// 富文本编辑器
Vue.use(VueQuillEditor /* { default global options } */)
// 配置axios默认网址
axios.defaults.baseURL = '/api'
// axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// axios拦截器
// 请求拦截
axios.interceptors.request.use(config => {
  NProgress.start()
  // Do something before request is sent
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
}, error => {
// Do something with request error
  return Promise.reject(error)
})
// 响应拦截
axios.interceptors.response.use(response => {
  NProgress.done()
  // Do something before response is sent
  // console.log(response)
  return response.data
}, error => {
// Do something with response error
  return Promise.reject(error)
})
// 将axios挂载到原型上去
Vue.prototype.$http = axios
// 定义时间过滤器
Vue.filter('dateFormat', function (val, format) {
  return moment.unix(val).format(format)
})
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
